package kr.haggenna.member.controller;

import java.util.ArrayList;
import java.util.List;

import kr.haggenna.item.dao.ItemDao;
import kr.haggenna.item.domain.Item;
import kr.haggenna.member.dao.MemberDao;
import kr.haggenna.member.domain.MemberCommand;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class UpdateFormController {
	@Autowired
	private MemberDao memberDao;
	@Autowired
	private ItemDao itemDao;
	
	@RequestMapping(value="/updateForm.do",method=RequestMethod.POST)
	public ModelAndView form(@RequestParam("email")String email){
		MemberCommand memberCommand = memberDao.getMember(email);
		
		ModelAndView mav = new ModelAndView();
		
		List<Item> itemList = new ArrayList<Item>();
		
		List<Item> bakeryList = itemDao.getBakeryList();
		List<Item> baverageList = itemDao.getBeverageList();
		List<Item> coffeeList = itemDao.getCoffeeList();
		
		for(Item item : coffeeList){
			itemList.add(item);
		}
		for(Item item : baverageList){
			itemList.add(item);
		}
		for(Item item : bakeryList){
			itemList.add(item);
		}
		
		mav.setViewName("updateForm");
		mav.addObject("memberCommand", memberCommand);
		mav.addObject("itemList", itemList);
		
		return mav;
	}
	
}
